/*-------------------- Includes -----------------------*/
#include <stdint.h>
#include "basic.h"
#include "FOC_PMSM.h"

/*------------------- Private variables ---------------*/
#define 	SEVENMODE		1
#define 	FIVEMODE		0

typedef struct {
			s32	Alpha;
			s32	Beta;
			s16	CompAU;
			s16	CompBU;
			s16	CompCU;
			s16	CompAD;
			s16	CompBD;
			s16	CompCD;
			u8	Sector;
			u8	PreSector;
			u8	Mode;
			s16	Period;
			u16 ADCTri0;
			u16 ADCTri1;
			u16	u16MinWidth;
			u16	u16MinTsDelay;
}PWM_GEN_T;


typedef struct
{
	int32_t Va;
	int32_t Vb;
	int32_t Vc;
	int32_t Vab;
	int32_t Vbc;
	int32_t Vca;
	int32_t Zero;
	int16_t Alpha;
	int16_t Beta;
	uint16_t Torque;
	int16_t	PreAngle;
	int16_t NewAngle;
	int32_t	SquareEs;				
	int16_t	We;
}
BEMFType;

extern int16_t s16Idc_offset;
extern int16_t s16Idc_tmp1;
extern int16_t s16Idc_tmp2;
extern int16_t s16PhaseCurrentU;
extern int16_t s16PhaseCurrentV;
extern int16_t s16PhaseCurrentW;
extern PWM_GEN_T pwm_gen;
extern BEMFType Bemf;

extern void PWM_GEN_init(PWM_GEN_T *u1);
extern void PWM_GEN_calc(PWM_GEN_T *u1);
extern void Update_PWM(PWM_GEN_T *u1);

extern void MCF_FlyStart_1R(FOC_TypeDef *pFOC);
extern void MCF_FlyStart_0BEMF(FOC_TypeDef *pFOC);
extern void MCF_ADV_Protect(FOC_TypeDef *pFOC);
extern void Reconstructed_3Phase_Current_for_1ShuntR(void);

extern int16_t Arctan(int16_t y1,int16_t x1);
extern void Bemf_Calc(BEMFType *u1);
extern void Fast_Boot_Current_Controller(FOC_TypeDef *pFOC);
extern uint8_t Fast_Boot_StartUp(FOC_TypeDef *pFOC);
extern uint8_t Fast_Boot_Spin(FOC_TypeDef *pFOC);
